package com.ruitu.mall_98_1.product.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.beanu.arad.base.BaseFragment;
import com.beanu.arad.base.my_base.base_list.ListBaseAdapter;
import com.ruitu.mall_98_1.R;
import com.ruitu.mall_98_1.product.activity.ProductDetailActivity;
import com.ruitu.mall_98_1.product.activity.ShopDetailActivity;
import com.ruitu.mall_98_1.product.adapter.ProductListAdapter;
import com.ruitu.router_module.bean.product.Product;
import com.ruitu.router_module.bean.product.ShopDetail;

//产品中心
public class ShopDetail3Fragment extends BaseFragment {
    private RecyclerView rcv_pro;
    protected TextView tv_copyright, tv_phone, tv_addr, tv_support;

    private ProductListAdapter adapter;
    private ShopDetail shopDetail;

    public static ShopDetail3Fragment newInstance(ShopDetail shopDetail) {
        Bundle args = new Bundle();
        args.putSerializable("shopDetail", shopDetail);
        ShopDetail3Fragment fragment = new ShopDetail3Fragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        adapter = new ProductListAdapter(getActivity());
        adapter.type = 2;//2 纵向双列
        shopDetail = (ShopDetail) getArguments().getSerializable("shopDetail");

        adapter.setOnItemClickListener(new ListBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int position) {
                Product product = shopDetail.getGoodsList().get(position);
                Bundle bundle = new Bundle();
                bundle.putSerializable("product", product);
                Intent intent = new Intent(getActivity(), ProductDetailActivity.class);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.pro_fragment_shop_detail_3, container, false);
        rcv_pro = v.findViewById(R.id.rcv_pro);
        tv_copyright = v.findViewById(R.id.tv_copyright);
        tv_phone = v.findViewById(R.id.tv_phone);
        tv_addr = v.findViewById(R.id.tv_addr);
        tv_support = v.findViewById(R.id.tv_support);

        ((ShopDetailActivity) getActivity()).setShopBottom(tv_copyright, tv_phone, tv_addr, tv_support);

        GridLayoutManager m = new GridLayoutManager(getActivity(), 2) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        rcv_pro.setLayoutManager(m);
        rcv_pro.setAdapter(adapter);
        adapter.setDataList(shopDetail.getGoodsList());

        return v;
    }
}
